Return to doc.sitecore.com

Valid for Sitecore 5.3, 5.2, 5.1.1
3.  Item Related Classes
Prev Next

Sitecore provides many classes which encapsulate both the content and infrastructure associated with a Site.  Nearly all information stored by Sitecore is represented as an Item, which can be seen as similar to a database record.  Some Items perform a specific function, such as Templates (which describe Items) or UserItems (which describe Users), others simply represent content managed by Sitecore and displayed on the published web site.

Regardless of their specific function or where they are stored, Sitecore refers to the storage mechanism for Items as a Database.  The actual physical implementation of the Database may vary and is described in more detail in the Integrating External Data Sources article.  Regardless of the actual implementation of the storage, developers retrieve Items, represented by the Sitecore.Data.Items.Item class, via the Sitecore.Data.Database class. 

As mentioned earlier, Items are similar to database records.  Items contain Fields, which are similar to database table columns.  All Fields are stored as XML text, but the various Sitecore data types use various formats and tags to structure the information appropriately (for more information related to the storage of each type, please refer to the Field Reference article).  Although it is always possible to extract the raw XML text directly from an Item, Sitecore provides a number of Field specific classes which parse the XML text to provide details about the Field contents.

3.1.  Sitecore.Data.Database

A Database consists mainly of a collection of Items, but also has associated Aliases, Indexes, Languages, Masters, Properties, Templates, and more.  This section describes the most commonly used members.  For more information, please refer to the complete reference section for Sitecore.Data.Database.

Items

Provides access to the Items in the Database.  Items may be accessed:

  • By Path:

    Sitecore.Data.Items.Item myItem =
      myDB.Items[“/sitecore/content/home/myitem”];

  • By GUID:

    Sitecore.Data.ID myItemID = Sitecore.Data.ID.Parse(
      "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}");

    myItem = Sitecore.Context.Database.Items[myItemID];

  • By GUID Path:

    string myItemURI =
      "/{11111111-1111-1111-1111-111111111111}"
      + "/{8374EDAF-2947-20C7-148B-20484EFFA87B}"
      + "/{38A98B93-39AB-983D-284A-39F87C938E84}"
      + "/{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}";
     
    myItem = Sitecore.Context.Database.Items[myItemURI];

Languages

An array of Sitecore.Globalization.Language, which represent the Languages supported by Items in this Database.

Name

The name of this database as a string.

Masters

A collection of Master Items represented as a Sitecore.Data.MasterRecords object.  Masters are used when creating content Items in the Sitecore clients.

Templates

A collection of Template Items represented as a Sitecore.Data.TemplateRecords object.  Templates define the Fields associated with a specific Item.

3.2.  Sitecore.Data.Items.Item

Items are similar to database records, but also similar to nodes in a hierarchy.  That is, Items have Fields, which are similar to relational database table columns, but Items may also have children.  All Items are based on a Template, which defines the Item’s Fields.  An Item’s children may be based on the same or different Templates. 

The commonly used class members include:

Access

Provides information related to user rights associated with this Item based on security and workflow settings.  Based on the Sitecore.SecurityModel.ItemAccess class, this member provides methods such as CanRead and CanWrite, which return a Boolean which indicates if the current user has the associated access right.

Children

A list of child Items represented by a Sitecore.Collections.ChildList, which provides access to the individual child Items, the count of children this Item has, and so on.

Database

The Sitecore.Data.Database object which contains this Item.

DisplayName

The name displayed for this Item in the Sitecore Content Editor content hierarchy.

Editing

Provides access to transaction editing features implemented by the Sitecore.Data.Items.ItemEditing class.

Fields

Provides access to the Fields associated with this Item as a Sitecore.Collections.FieldCollection.

HasChildren

A Boolean indicating if this Item has child Items.

ID

The GUID associated with this Item.

Key

The display name of this item in all lower case characters.

Language

The Language of the content in this Item as a Sitecore.Globalization.Language object.

Languages

An array of the languages this Item may have content for.

Name

A short textual description of the Item, like a filename in a file system.

Parent

The parent of this Item in the content hierarchy.  For the root Item, the parent is set to null.

ParentID

The ID of this Item’s parent as a Sitecore.Data.ID object.

Paths

A Sitecore.Data.ItemPath object which describes the path of this Item.  Use the Paths member to access the FriendlyUrl of the Item (GetFriendlyUrl).

Template

The Template that this Item is based on as a Sitecore.Data.Items.TempalteItem object.

TemplateID

The ID of the Template that this Item is based on as a Sitecore.Data.ID object.

TemplateName

The Name of the Template that this Item is based on as a string.

Uri

The Uri (address) of the Item as a Sitecore.Data.ItemUri object.

Version

Gets the Version object of this Item as a Sitecore.Data.Version.

Versions

Gets all the Versions of the Item as a Sitecore.Data.ItemVersions object.

The Item class also includes a number of methods for creating, modifying, and deleting Items.  These methods are not described here as these are mostly used from within the Sitecore client, which is an advanced function and is beyond the scope of this article.

3.3.  Sitecore.Data.Fields.*

The Sitecore.Data.Fields namespace includes a number of data type specific classes that provide access to methods that interpret the value stored in a given Field.  Note that this is useful because Sitecore stores all data as XML text with various tag formats.  For some field data types, such as Text, the field value is stored as a raw text value.  For others, such as the Date data type, the value is formatted and should probably be reformatted when rendering.  The Fields namespace includes classes that make this reformatting easy.

For more information, please refer to the Field Reference article


Prev Next